package com.itheima.springboot_24_mq.service.impl.kafka.listense;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.KafkaListeners;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

@Component //要能够被springboot加载
public class MessageListener {
    //@KafkaListeners({@KafkaListener(topics = "itheima"),@KafkaListener(topics = "itheima2")}) //指定消息队列的名称,可以是个数组,即监听多个队列
    @KafkaListener(topics = {"itheima","itheima2"})//指定消息队列的名称,可以是个数组,即监听多个队列
    @SendTo("itheima3")//这是在本方法执行完后,将本方法的结果发往下一个待处理的队列
    public String receive(ConsumerRecord<String,String> record){
        System.out.println("lisentener从队列中达到了消息:"+record.value());
        return record.value()+1;
    }
    @KafkaListener(topics = "itheima3") //指定消息队列的名称,可以是个数组,即监听多个队列
    public void receive2(ConsumerRecord<String,String> record){
        System.out.println("lisentener从队列中达到了消息2:"+record.value());
    }
}
